from dataclasses import dataclass
import pickle, datetime

class Lodger:
    def __init__(self):
        self.items = dict()
        self.storage = PickleStorage(self)
        self.maxID = 0
        
    def store(self):
        self.storage.store()

    def load(self):
        self.storage.load()

    def addItem(self):
        self.maxID += 1
        item = LodgerItem(id=self.maxID)
        item.read()
        self.items[item.id] = item

    def output(self):
        for id, item in self.items.items():
            item.write()

    def deleteItem(self):
        id = int(input("id: "))
        del self.items[id]

class ConsoleIO:
    def input(self, field, default=None):
        return input(f"{field}: ")
    
    def output(self, title, field):
        print(f"{title}: {field}")

class PickleStorage:
    def __init__(self, lodger):
        self.lodger = lodger
    
    def store(self):
        pickle.dump((self.lodger.maxID, self.lodger.items), open("data.dat", "wb"))
        
    def load(self):
        (self.lodger.maxID, self.lodger.items) = pickle.load(open("data.dat", "rb"))

@dataclass
class LodgerItem:
    id: int = 0
    fio: str = ""
    room: str = ""
    count: str = ""
    time = 0
    child: str = ""
    
    def __post_init__(self):
        self.time = datetime.datetime.now()
        self.io = ConsoleIO()
        
    def read(self):
        self.fio = self.io.input('fio')
        self.room = self.io.input('room')
        self.count = self.io.input('count')
        self.child = self.io.input('child')
        
    def write(self):
        self.io.output('ID', self.id)
        self.io.output('FIO', self.fio)
        self.io.output('Room', self.room)
        self.io.output('Count', self.count)
        self.io.output('Time', self.time)
        self.io.output('Child', self.child)
        
        
def main():
    lodger = Lodger()
    
    menu = [
        ["Добавить", lodger.addItem],
        ["Удалить", lodger.deleteItem],
        ["Показать", lodger.output],
        ["Сохранить", lodger.store],
        ["Загрузить", lodger.load],
    ]

    while True:
        for i,menuItem in enumerate(menu, 1):
            print(f"{i}. {menuItem[0]}")
        m = int(input())
        menu[m-1][1]()

main()